/**
 * 
 */
package org.abrysov.android.essenceofgita.activity;

import org.abrysov.android.essenceofgita.MainActivity;
import org.abrysov.android.essenceofgita.R;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;
import android.widget.TextView;

/**
 * @author Alexander Brysov
 *
 */
public class Chapter01 extends Activity {

//	private TextView mText = null;
//	private Typeface mTextType = null;
	
	private WebView mWebView = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.chapter01_);
		
//		mTextType = Typeface.createFromAsset(getAssets(), "fonts/scagrg__.ttf");
//		
//		mText = (TextView)findViewById(R.id.ch01_tv_text);
//		mText.setTypeface(mTextType, Typeface.NORMAL);
		
		SharedPreferences pref = getSharedPreferences(MainActivity.LOCAL_DATA, 0);
		
		mWebView = (WebView)findViewById(R.id.chapter01_wv);
		
		if (pref.getBoolean("en", true) == true){
			mWebView.loadUrl("file:///android_asset/chapter_01_en.html");
		}else{
			mWebView.loadUrl("file:///android_asset/chapter01.html");
		}
		 //chapter_01_en.html |chapter01.html 
		
		startActivity(new Intent(getApplicationContext(), Prechapter.class));
		
	}
	
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    	String donate = getResources().getString(R.string.menu_donate);
    	String review = getResources().getString(R.string.menu_review);
    	
    	menu.add(Menu.NONE, MainActivity.MENU_DONATE_ID, Menu.NONE , donate);
    	menu.add(Menu.NONE, MainActivity.MENU_COMMENT_ID, Menu.NONE , review);
    	
        return true;
    }
    
    @Override
    public boolean onMenuItemSelected(int featureId, MenuItem item) {
//    	return super.onMenuItemSelected(featureId, item);
    	
    	switch (item.getItemId()) {
		case MainActivity.MENU_DONATE_ID:
			startActivity(new Intent(getApplicationContext(), Donate.class));
			break;

		case MainActivity.MENU_COMMENT_ID:
		   	 String appPackageName=getResources().getString(R.string.app_package_name);
		   	 Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+appPackageName));
		   	 marketIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
		   	 startActivity(marketIntent);
			break;
			
		default:
			break;
		}
    	
    	return true;
    
    }
	
}
